-
Notifications
You must be signed in to change notification settings - Fork 148
fix: Replace custom language names list with standard Intl DisplayNames API #2332 #2371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
fd2e479
to
752cb2d
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2371 +/- ##
==========================================
+ Coverage 94.44% 94.49% +0.05%
==========================================
Files 1169 1169
Lines 25102 25149 +47
Branches 5473 5492 +19
==========================================
+ Hits 23708 23765 +57
+ Misses 1328 1320 -8
+ Partials 66 64 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
752cb2d
to
dd4af33
Compare
dd4af33
to
9f4da76
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! Could you please finish updating the PR description? I was hoping you could explain some of your decisions a bit, like why you added the new iso-639-1
dependency.
@@ -18,7 +18,7 @@ | |||
"start": "fedx-scripts webpack-dev-server --progress", | |||
"start:with-theme": "paragon install-theme && npm start && npm install", | |||
"dev": "PUBLIC_PATH=/authoring/ MFE_CONFIG_API_URL='http://localhost:8000/api/mfe_config/v1' fedx-scripts webpack-dev-server --progress --host apps.local.openedx.io", | |||
"test": "TZ=UTC fedx-scripts jest --coverage --passWithNoTests", | |||
"test": "TZ=UTC fedx-scripts jest --passWithNoTests", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"test": "TZ=UTC fedx-scripts jest --passWithNoTests", | |
"test": "TZ=UTC fedx-scripts jest --coverage --passWithNoTests", |
I think you committed this accidentally? I find the --coverage
check here to be annoying as well, but we can't just change it without a dedicated PR and a bit more discussion.
import { FileInput, fileInput } from '../../../../../../sharedComponents/FileInput'; | ||
import { getLanguageName } from '../../../../../../data/constants/video'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { getLanguageName } from '../../../../../../data/constants/video'; | |
import { getLanguageName } from '@src/editors/data/constants/video'; |
This is simpler - see the best practices checklist in the PR description.
@@ -45,27 +45,27 @@ export const hooks = { | |||
}; | |||
|
|||
const LanguageSelector = ({ | |||
index, // For a unique id for the form control |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please leave this comment in place; I think it's helpful.
language, | ||
// Redux | ||
openLanguages, // Only allow those languages not already associated with a transcript to be selected | ||
openLanguages, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add back a comment to explain this parameter.
@@ -46,13 +49,4 @@ describe('LanguageSelector', () => { | |||
render(<LanguageSelector {...props} language="" />); | |||
expect(screen.getByText('Select Language')).toBeInTheDocument(); | |||
}); | |||
|
|||
test('transcripts no Open Languages, all dropdown items should be disabled', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this test no longer needed?
za: 'Zhuang', | ||
zu: 'Zulu', | ||
}); | ||
export const getLanguageName = (langCode, locales = ['en']) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can't convert this file to TypeScript yet, please move this function to a separate language-utils.ts
file that is using TypeScript so that you can document the types properly. Any significant new code like this should have types defined. (And if you can't move it to a .ts file or convert this file to .ts you can always add JSDoc type comments.)
export const openLanguagesDataSet = ISO6391.getAllCodes().reduce((acc, code) => { | ||
acc[code] = ISO6391.getName(code); | ||
return acc; | ||
}, {}); | ||
|
||
export const in8lTranscriptLanguages = (intl) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this in8lTranscriptLanguages
code anymore. You can already use getLanguageName
(the Intl.DisplayNames
API) to get the name of a language in any other language.
|
||
export const in8lTranscriptLanguages = (intl) => { | ||
const messageLookup = {}; | ||
// for tests and non-internationlized setups, return en | ||
|
||
// For tests and non-internationalized setups, return raw dataset |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node.js supports Intl.DisplayNames
so it should work in tests too.
}); | ||
|
||
it('returns language name from Intl.DisplayNames for given locale', () => { | ||
displayNamesSpy = jest.spyOn(global.Intl, 'DisplayNames').mockImplementation(() => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to mock it?
// Fallback to ISO6391 if Intl.DisplayNames fails | ||
} | ||
} | ||
const isoName = ISO6391.getName(code); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we include ISO6391 as a dependency, it undoes the bundle size savings of removing the language names from our code. Did you find a case where the Intl.DisplayNames API was not working, and this fallback is necesesary?
I think we should just fall back to (A) Intl.DisplayNames response but for English instead of the user's locale, and (B) if that doesn't work, just return the language code as the language name.
Description
Replace custom language names list with standard Intl DisplayNames API #2332
Supporting information
Link to other information about the change, such as GitHub issues, or Discourse discussions.
Be sure to check they are publicly readable, or if not, repeat the information here.
Testing instructions
Please provide detailed step-by-step instructions for manually testing this change.
Other information
Include anything else that will help reviewers and consumers understand the change.
Best Practices Checklist
We're trying to move away from some deprecated patterns in this codebase. Please
check if your PR meets these recommendations before asking for a review:
.ts
,.tsx
).propTypes
,defaultProps
, andinjectIntl
patterns are not used in any new or modified code.src/testUtils.tsx
(specificallyinitializeMocks
)apiHooks.ts
in this repo for examples.messages.ts
files have adescription
for translators to use.../
. To import from parent folders, use@src
, e.g.import { initializeMocks } from '@src/testUtils';
instead offrom '../../../../testUtils'